package com.chendx.store.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chendx.model.goods.dto.SkuDto;
import com.chendx.model.goods.pojo.Sku;
import com.chendx.model.order.pojo.OrderItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * Created by chendx on 2022/4/18.
 */
@Mapper
public interface SkuMapper extends BaseMapper<Sku>{

    /**
     * 库存递减
     * @param orderItem
     * @return
     */
    @Update("update tb_sku set num=num-#{num},sale_num=sale_num+#{num} where id =#{skuId} and num >=#{num}")
    public int decrCount(OrderItem orderItem);

    /**
     * 库存回滚
     * @param orderItem
     * @return
     */
    @Update("update tb_sku set num=num+#{num},sale_num=sale_num-#{num} where id =#{skuId}")
    public int incrCount(OrderItem orderItem);

    /**
     * 修改sku的价格
     * @param dto
     * @return
     */
    @Update("update tb_sku set price = #{price} where id = #{skuId}")
    public int updatePrice(SkuDto dto);

}
